package com.example.kotlinstudy.基本类型

val one = 1
val threeBillion = 30000000000
val oneLong = 1L
val oneByte: Byte = 1
val pi = 3.14
val oneDouble = 1.0
val e = 2.7111111111
val eFloat = 2.71545353454f
val oneMillin = 1_000_000
val creditCardNumber = 1234_5678_9012_3456L
val socialSecurityNumber = 999_99_9999L
val hexBytes = 0xFF_EC_DE_5E
val bytes = 0b11010010_01101001_10010100_10010010
fun main() {
    fun printDouble(d: Double) {
        println(d)
    }

    val i = 1
    val d = 1.0
    val f = 1.0f
    printDouble(d)
    println(oneMillin)

    ///JVM
    ///由于 JVM 对 -128 到 127 的整数（Integer）应用了内存优化，因此，a 的所有可空引用实际上都是同一对象。但是没有对 b 应用内存优化，所以它们是不同对象
    val a: Int = 10000
    //val a: Int = 10000
    val boxedA: Int? = a
    val anotherBoxA: Int? = a
    println(boxedA == anotherBoxA)
    //println(boxedA === anotherBoxA)

    //显示数字转换
    val b: Byte = 1
    val i1: Int = b.toInt()
    //很多请款无需显示类型转换
    val l = 1L + 3
    //数字运算
    println(1 + 2)
    println(2_500_000_000L - 1L)
    println(3.14 * 2.71)
    println(10.0 / 3)
    //整数除法
    val x = 5 / 2
    //println(x == 2.5) // ERROR: Operator '==' cannot be applied to 'Int' and 'Double'
    println(x == 2)
    val x1 = 5L / 2
    println(x1 == 2L)
    val x3 = 5 / 2.toDouble()
    println(x3 == 2.5)
    //位运算
    val x4 = (1 shl 2) and 0x000FF000
    //浮点数比较
    println(Double.NaN == Double.NaN)                 // false
    println(listOf(Double.NaN) == listOf(Double.NaN)) // true
    println(0.0 == -0.0)                              // true
    println(listOf(0.0) == listOf(-0.0))              // false
    println(listOf(Double.NaN, Double.POSITIVE_INFINITY, 0.0, -0.0).sorted())
}